package com.mirabelle.juice.service;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mirabelle.juice.dao.AuthorDao;
import com.mirabelle.juice.model.Author;

@Service("AuthorService")
public class AuthorServiceImpl implements AuthorService, Serializable {
	private static final long serialVersionUID = 1L;

	@Autowired
	AuthorDao authorDao;

	@Override
	public Author findAuthorByUniqueIdentifier(String identifier) {
		Author a = authorDao.getOneByNickName(identifier);
		if (null == a) {
			a = authorDao.getOneByMail(identifier);
		}
		return a;
	}

	@Override
	public Author findAuthorByMail(String mail) {
		return authorDao.getOneByMail(mail);
	}

	@Override
	public Author findAuthorByNickName(String nickName) {
		return authorDao.getOneByNickName(nickName);
	}

	@Override
	public Author register(Author author) {
		authorDao.saveAuthor(author);
		return findAuthorByUniqueIdentifier(author.getMail());
	}

	@Override
	public void reload(Author author) {
		authorDao.reload(author);
	}
}
